package com.pine.dbant.core.web;

import com.pine.dbant.core.model.dto.DirectoryDTO;
import com.pine.dbant.core.model.vo.DirTreeVO;
import com.pine.dbant.core.service.DirectoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author xiaoyuan
 * @create 2022/11/29 11:24
 **/
@RestController
@RequestMapping("/directory")
@Api(tags = "目录")
public class DirectoryController extends BaseHandler {
    @Autowired
    private DirectoryService directoryService;

    /**
     * 获取目录和连接树信息
     *
     * @return
     */
    @ApiOperation("目录和连接树信息")
    @GetMapping("/getConnTree")
    public List<DirTreeVO> getConnTree() {
        return directoryService.getConnTree();
    }

    /**
     * 获取目录树信息
     *
     * @return
     */
    @ApiOperation("目录树信息")
    @GetMapping("/getDirTree")
    public List<DirTreeVO> getDirTree() {
        return directoryService.getDirTree();
    }

    /**
     * @param resId
     * @param targetId
     */
    @ApiOperation("移动")
    @PostMapping("/move")
    public void move(@NotNull(message = "源id不能为空") Long resId, @NotNull(message = "源类型不能为空") DirTreeVO.Type resType,@NotNull(message = "目标id不能为空") Long targetId) {
        directoryService.move(resId, resType, targetId);
    }

    /**
     * 保持目录
     *
     * @param directoryDTO
     */
    @ApiOperation("保存")
    @PostMapping("/save")
    public void save(@Valid @RequestBody DirectoryDTO directoryDTO) {
        directoryService.save(directoryDTO);
    }


    /**
     * 更新目录
     *
     * @param directoryDTO
     */
    @ApiOperation("更新")
    @PostMapping("/update")
    public void update(@Valid @RequestBody DirectoryDTO directoryDTO) {
        directoryService.update(directoryDTO);
    }


    /**
     * 根据id删除目录
     *
     * @param dirId
     */
    @ApiOperation("删除")
    @PostMapping("/deleteById")
    public void deleteById(@NotNull(message = "id不能为空") Long dirId) {
        directoryService.deleteById(dirId);
    }
}
